# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libvorbisidec
pkgbase=mingw-w64-${_realname}-svn
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-svn"
_revision=
_fragment=
[[ -n ${_revision} ]] && _fragment="#revision=${_revision}"
pkgver=r19643
pkgrel=1
pkgdesc='Integer-only Ogg Vorbis decoder, AKA \"tremor\" (mingw-w64)'
arch=('any')
url='https://svn.xiph.org/trunk/Tremor'
license=('custom')
depends=("${MINGW_PACKAGE_PREFIX}-libogg")
makedepends=("subversion" "${MINGW_PACKAGE_PREFIX}-gcc")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
options=('strip' 'staticlibs' '!emptydirs')
source=("${_realname}"::"svn+https://svn.xiph.org/trunk/Tremor/${_fragment}"
        0001-add-no-undefined-for-libtool.mingw.patch
        0002-no-configure-in-autogen.mingw.patch
        0003-update-ac.mingw.patch)
sha256sums=('SKIP'
            '5c5f30ceef0dfa9e33b71b8b475ee79e4c15a10d311ad92c56df459070dd8abd'
            'dde8d0a8cdbec73476959454cd6ef303677be304da0a3b1b7c23066d666a7bf3'
            'e831885ef703c4600fd0e330d1f77943866c35af53e9c5e39406aaf8e124d27c')

pkgver() {
  cd "${srcdir}/${_realname}"
  local ver="$(svnversion)"
  printf "r%s" "${ver//[[:alpha:]]}"
}

prepare() {
  cd ${srcdir}/${_realname}
  patch -p1 -i ${srcdir}/0001-add-no-undefined-for-libtool.mingw.patch
  patch -p1 -i ${srcdir}/0002-no-configure-in-autogen.mingw.patch
  patch -p1 -i ${srcdir}/0003-update-ac.mingw.patch

  ./autogen.sh
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}
    make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install
}
